[lua] Add lua.Lib.getModuleVarargs() for module-level varargs capture#12602
[lua] Add lua.Lib.getModuleVarargs() for module-level varargs capture#12602jdonaldson wants to merge 1 commit intoHaxeFoundation:developmentfrom
Conversation
|
Sys.args() documentation states:
If Sys.args() can now contain values passed using loadfile instead of via the cli, then it is deviating from the specified behaviour. Also, just because Expand for sample lua code where this can occur-- wrapper.lua
local main = loadfile("main.lua")
main("load", "file", "args")-- main.lua
print("_G.arg = " .. table.concat(_G.arg, " "))
print("{...} = " .. table.concat({...}, " "))$ lua wrapper.lua real cli args
_G.arg = real cli args
{...} = load file argsI also think it's bad practice to overwrite a global value like We should also avoid injecting more unconditionally included lua code. Even if it's one line now, it builds up gradually and one of the most common complaints about the lua target is the boilerplate required for simple programs. It is especially something to consider when only some users need it but it is added to everyone's code. Using define feature here to conditionally generate the extra line avoids this problem. Maybe it's better to have a new method like |
ed03f19 to
fd80412
Compare
Replaces the unconditional _G.arg overwrite with an opt-in API. The runtime helper is only included when getModuleVarargs() is used.
fd80412 to
79bf1d2
Compare
|
Finished up a total rewrite. This uses a lua feature module to capture the args, rather than capturing it at the start of every script. |
Summary
...(varargs) rather than populating_G.arg. The generated Lua wraps everything in functions, so...becomes inaccessible.lua.Lib.getModuleVarargs()— an opt-in API that returns the module-level varargs as aTable<Int, String>. Users can convert to an array withTable.toArray()._hx_module_varargs = {...}) is only included in the output whengetModuleVarargs()is actually used (gated behind DCE feature detection).Test plan
make haxebuilds successfullygetModuleVarargs()captures args when invoked aslua script.lua arg1 arg2getModuleVarargs()is not called